package ec2deployexample;

import net.chrisrichardson.ec2deployer.core.AWSProperties
import net.chrisrichardson.ec2deployer.core.EC2
import net.chrisrichardson.ec2deployer.core.EC2InstanceType
import net.chrisrichardson.ec2deployer.applications.CatalinaOptionsBuilder;
import net.chrisrichardson.ec2deployer.cluster.*

class ExampleEC2DeployTest extends GroovyTestCase {

    void testSomething() {
        AWSProperties awsProperties = new AWSProperties(System.getProperty('ec2deploy.aws.properties'))
        def ec2 = new EC2(awsProperties)

        def explodedWar = 'h:/cer/code/j2eebook/projecttrack/webapp/target/ptrack'

        ClusterSpec clusterSpec = new ClusterSpec()
                                        .tomcats(1)
                                        .instanceType(EC2InstanceType.SMALL)
                                        .slaves(1)
                                        .webApp(explodedWar, "ptrack")
                                        .catalinaOptsBuilder("""{builder, databasePrivateDnsName, slaves ->
                                                                builder.arg("-Xmx500m")
                                                                builder.prop("com.sun.management.jmxremote")
                                                                builder.prop("com.sun.management.jmxremote.port", 8091)
                                                                builder.prop("com.sun.management.jmxremote.authenticate", false)
                                                                builder.prop("com.sun.management.jmxremote.ssl", false)
                                                                builder.prop("ptrack.application.environment", "ec2")
                                                                builder.prop("log4j.configuration", "log4j-minimal.properties")
                                                                builder.prop("jdbc.db.server", databasePrivateDnsName)}""")
                                        .schema("ptrack", ["ptrack": "ptrack"], ["src/test/resources/testdml1.sql", "src/test/resources/testdml2.sql"])
        SimpleCluster cluster = new SimpleCluster(ec2, clusterSpec)

        cluster.start(true)

        cluster.dumpInfo()

        def jmeterTest = "h:/cer/code/j2eebook/projecttrack/functionalTests/jmeter/SimpleTest.jmx"
        cluster.loadTest(jmeterTest, [1])
    }
    
}
